package org.emavaj.sanguosha.controller.card;

import java.util.LinkedList;
import java.util.List;

import org.emavaj.sanguosha.model.card.AbstractCard;
import org.emavaj.sanguosha.view.gameview.GameFrame;

/**
 * 
 * @author eMavaj
 * 
 */
public class HandoutCardController {

	private List<AbstractCard> selectedCardList = new LinkedList<AbstractCard>();

	private int maxSelectCnt = 1;
	
	private GameFrame owner;

	public HandoutCardController(GameFrame owner) {
		this.owner = owner;
	}

	public boolean isSelectedNoCard() {
		return selectedCardList.size() == 0;
	}

	private AbstractCard getFirstCard() {
		return selectedCardList.get(0);
	}

	public void removeOneCard(AbstractCard card) {
		selectedCardList.remove(card);
	}

	public void addOneCard(AbstractCard card) {
		selectedCardList.add(card);
	}

	public boolean canSelectMore() {
		return selectedCardList.size() < maxSelectCnt;
	}

	public AbstractCard getPlayCard() {
		//if (selectedCardList.size() == 1) {
			return getFirstCard();
		//} else {
			// 用第一张牌融合其它牌，成为一张牌
		//	return getFirstCard().combineCard(selectedCardList);
		//}
	}

	public List<AbstractCard> getPlayCardList() {
		return selectedCardList;
	}

	public int getMaxSelectCnt() {
		return maxSelectCnt;
	}

	public int selectCardCnt() {
		return selectedCardList.size();
	}

	public void setMaxSelectCnt(int maxSelectCnt) {
		this.maxSelectCnt =  maxSelectCnt < 0 ? 0 : maxSelectCnt;
	}

	public void clear() {
		// Iterator<AbstractCard> its = selectedCardList.iterator();
		// while (its.hasNext()) {
		// its.remove();
		// }
		selectedCardList = null;
		selectedCardList = new LinkedList<AbstractCard>();
	}
}
